define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dailishang/index' + location.search,
                    add_url: 'dailishang/add',
                    edit_url: 'dailishang/edit',
                    del_url: 'dailishang/del',
                    multi_url: 'dailishang/multi',
                    import_url: 'dailishang/import',
                    table: 'dailishang',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'jingli.name', title: __('Jingli.name'), operate: 'LIKE'},
                        {field: 'userhome.nickname', title: __('代理商名称'), operate: 'LIKE'},
                        // {field: 'jingli_id', title: __('Jingli_id')},
                        // {field: 'uid', title: __('Uid')},
                        {field: 'huikuan', title: __('Huikuan'), operate: 'LIKE'},
                        {field: 'storenum', title: __('Storenum')},
                        {field: 'c_num', title: __('普通会员')},
                        {field: 'vouchers', title: __('Vouchers'), operate:false},
                        {field: 'hezuotime', title: __('Hezuotime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'id', title: __('县域合伙人(认证的小店)'), formatter: Controller.api.formatter.id,operate:false},
                        {field: 'city', title: __('City'), operate: 'LIKE'},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                search:false,
                showColumns: false,
                showToggle: false,
                // showExport: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                id: function (value, row, index) {
                    //这里手动构造URL
                    var ids = row['uid'];
                    // var store_id = row['store_id'];
                    
                    url = "userstore2?daili_id=" + ids;
                    //方式一,直接返回class带有addtabsit的链接,这可以方便自定义显示内容

                    return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("查看店铺", value) + '">' + '查看店铺' + '</a>';
                }
            }
        }
    };
    return Controller;
});